package com.wms.api.service.impl;

import com.wms.api.domian.*;
import com.wms.api.service.SfService;
import com.wms.api.sfApi.SfApiClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 顺丰服务实现类
 */
@Slf4j
@Service
public class SfServiceImpl implements SfService {

    @Autowired
    private SfApiClient sfApiClient;

    /**
     * 创建顺丰订单
     */
    @Override
    public SfOrderResponse createOrder(SfOrderRequest request) {
        log.info("创建顺丰订单, 订单信息: {}", request);
        // 调用顺丰API的下单接口，服务编码根据顺丰文档填写
        return sfApiClient.callApi("EXP_RECE_CREATE_ORDER", request, SfOrderResponse.class);
    }

    /**
     * 查询物流轨迹
     */
    @Override
    public SfRouteResponse queryRoute(String waybillNo) {
        log.info("查询顺丰物流轨迹, 运单号: {}", waybillNo);
        
        // 构建查询参数
        Map<String, Object> request = new HashMap<>();
        request.put("trackingType", "1"); // 1表示按运单号查询
        request.put("trackingNumber", new String[]{waybillNo});
        
        // 调用顺丰API的轨迹查询接口
        return sfApiClient.callApi("EXP_RECE_SEARCH_ROUTE", request, SfRouteResponse.class);
    }

    /**
     * 查询时效标准及价格
     */
    @Override
    public SfDeliveryTimeResponse queryDeliveryTime(SfDeliveryTimeRequest request) {
        log.info("查询时效标准及价格, 请求信息: {}", request);
        // 调用顺丰API的时效价格查询接口
        return sfApiClient.callApi("EXP_RECE_QUERY_DELIVERTM", request, SfDeliveryTimeResponse.class);
    }
}
